package common;

import java.io.Serializable;

/**
 * Class represents an identificator of longcat core data unit. <br>
 * This kind of simplification is completely sufficient for our needs. <br>
 * It implements basic methods used frequently in the rest of the code.<br>
 * Class implements interface Serializable for it is often a return object of return method. 
 */
public final class PackageID implements Serializable {
	/**
	 * This field is responsible for identification of a file this package is a part of.
	 */
	public final int fileID;
	/**
	 * This filed is responsible for identification of a sequence number of a packege.
	 * It is used to determine the order of the packages that are assembled into a file. 
	 */
	public final int partID;
	/**
	 * Basic constructor of a class.
	 * @param fileID A file this package is a part of. 
	 * @param partID Order number of a package.
	 */
	public PackageID(int fileID, int partID) {
		this.fileID = fileID;
		this.partID = partID;
	}
	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object rhs) {
		return rhs != null 
			&& rhs instanceof PackageID 
			&& fileID == ((PackageID)rhs).fileID 
			&& partID == ((PackageID)rhs).partID;
	}
	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		return fileID * 3 + partID * 31;
	}
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() { 
		return "" + fileID + "." + partID;
	}
}
